let source = "WDJ9E64LCPMNGZBVST58A72XQFIHK3YOUR";
let char = "tgxniafocyvbpewuhrkmdjzsq";

function createCode(id, len=6)
{
    let num = id;
    let code = '';
    while(num)
    {
        let mod = num % source.length; 
        num = (num - mod) / source.length;
        code += source.charAt(mod);
    }
    let count = code.length;
    if (count < len) {
        for (let i = 0; i < len-count; i++) {
            code += char.charAt(parseInt(char.length*Math.random()));
        }
    }
    return code;
}

module.exports = createCode;

// function randArr(arr) {
//     for (let i = 0; i < arr.length; i++) {
//         let iRand = parseInt(arr.length * Math.random());
//         let temp = arr[i];
//         arr[i] = arr[iRand];
//         arr[iRand] = temp;
//     }
//     return arr;
// }
// function randStr(arr) {
//     let ret = randArr(arr);
//     let str = "";
//     for (let i = 0; i < ret.length; i++) {
//         str += ret[i];
        
//     }
//     return str;
// }
// console.log(randStr(['2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']));
// console.log(randStr(['a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z']));